class Solution {
public:
    int calc(int n) {
        if (n / 10 == 0) return n;
        int sum = 0;
        while (n) {
            sum += n % 10;
            n /= 10;
        }
        return calc(sum);
    }
    int addDigits(int num) {
        return calc(num);
    }
};
